package com.leonzhangxf.bucksdemo.order.domain.value;

import com.google.common.collect.Lists;

import java.util.List;

public enum OrderStatus {

    /**
     * 生成
     */
    GENERATED {
        @Override
        public boolean statusReachable(OrderStatus targetStatus) {
            final List<OrderStatus> reachableStatus = Lists.newArrayList(PAYING, CLOSED, EXPIRED);
            return reachableStatus.contains(targetStatus);
        }
    },

    /**
     * 正在支付
     */
    PAYING {
        @Override
        public boolean statusReachable(OrderStatus targetStatus) {
            final List<OrderStatus> reachableStatus = Lists.newArrayList(PAID, CLOSED, EXPIRED);
            return reachableStatus.contains(targetStatus);
        }
    },

    /**
     * 已支付
     */
    PAID {
        @Override
        public boolean statusReachable(OrderStatus targetStatus) {
            final List<OrderStatus> reachableStatus = Lists.newArrayList(EFFECTED, REFUND);
            return reachableStatus.contains(targetStatus);
        }
    },

    /**
     * 生效
     */
    EFFECTED,

    /**
     * 退费
     */
    REFUND,

    /**
     * 关闭
     */
    CLOSED,

    /**
     * 过期
     */
    EXPIRED;

    /**
     * 判断是否可以变更为指定状态
     *
     * @param targetStatus 指定订单状态
     * @return 是否可以变更？
     */
    public boolean statusReachable(OrderStatus targetStatus) {
        return false;
    }
}
